package com.example.figurehecheng.controller.merchant;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.figurehecheng.common.result.PageResult;
import com.example.figurehecheng.common.result.Result;
import com.example.figurehecheng.domain.dto.couponDTO;
import com.example.figurehecheng.domain.entity.Coupon;
import com.example.figurehecheng.domain.vo.CouponVO;
import com.example.figurehecheng.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 宇科工作室
 * @since 2024-10-18
 */
@RestController
@RequestMapping("/merchant/coupon")
@CrossOrigin
@Api("优惠券")
@RequiredArgsConstructor
public class CouponController {

    private final ICouponService couponService;

    /**
     * 搜索优惠券
     * @param couponName
     */
    @GetMapping("/querySearch")
    @ApiOperation(value = "查询优惠券")
    public Result<List> querySearch(@RequestParam ("couponName") String couponName){
        List<CouponVO> couponVOS = couponService.querySearch(couponName);
        return Result.success(couponVOS);
    }

    /**
     * 查询所有优惠券
     */
    @GetMapping("/queryCoupon")
    @ApiOperation("获取所有优惠券")
    public Result<PageResult> queryCoupon(@RequestParam("pageNum") Integer pageNum,
                                    @RequestParam("pageSize")Integer pageSize){
        PageResult pageResult = couponService.queryCoupon(pageNum, pageSize);
        return Result.success(pageResult);
    }

    /**
     * 添加优惠券
     * @param couponDto
     */
    @PostMapping("/addCoupon")
    @ApiOperation("添加优惠券")
    public Result addCoupon(@RequestBody couponDTO couponDto) {
        couponService.addCoupon(couponDto);
        return  Result.success();
    }

    /**
     * 修改优惠券
     * @param couponDto
     */
    @PostMapping("/updateCoupon")
    @ApiOperation("修改优惠券")
    public Result updateCoupon(@RequestBody couponDTO couponDto) {
        System.out.println(couponDto);
        couponService.updateCoupon(couponDto);
        return Result.success();
    }

    /**
     * 删除优惠券
     * @param id
     */
    @DeleteMapping("/deleteCoupon")
    @ApiOperation("删除优惠券")
    public Result deleteCoupon(@RequestParam("id") Integer id) {
        couponService.deleteCoupon(id);
        return Result.success();
    }
}
